package com.geekaca.d07.test_stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class StreamTest1 {
    public static void main(String[] args) {
//        oldStyle();
        List<String> names = new ArrayList<>();
        Collections.addAll(names, "张三丰", "张无忌", "周芷若", "赵敏", "张强");
        names.stream().filter(item -> item.startsWith("张")).filter(item -> item.length() == 3).forEach(item-> System.out.println(item));
        List<String> 张 = names.stream().filter(item -> item.startsWith("张")).filter(item -> item.length() == 3).toList();
//        System.out.println(张.toList());
        System.out.println(张);

    }

    public static void oldStyle() {
        List<String> names = new ArrayList<>();
        Collections.addAll(names, "张三丰", "张无忌", "周芷若", "赵敏", "张强");
        // 1.找姓张的
        List<String> zhangList = new ArrayList<>();
        for (String name : names) {
            if (name.startsWith("张")) {
                zhangList.add(name);
            }
        }

        //2.张姓里找长度是3的
        List<String> zhangThreeList = new ArrayList<>();
        for (String name : zhangList) {
            if (name.length() == 3) {
                zhangThreeList.add(name);
            }
        }
        System.out.println(zhangThreeList);

    }
}
